package org.mc.sbd.mqredis.listener;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.mc.sbd.mqredis.event.MqEvent;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Component;

@Component
public class Event1Listener implements MessageListener {
    private final ObjectMapper objectMapper;

    public Event1Listener(ObjectMapper objectMapper) {
        this.objectMapper = objectMapper;
    }

    @Override
    public void onMessage(Message message, byte[] pattern) {
        try {
            MqEvent event = objectMapper.readValue(message.toString(), MqEvent.class);

            System.out.println("Event1Listener 收到：" + event.getContent());
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }
}
